﻿// Google analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18944523-1']);
_gaq.push(['_trackPageview']);

(function () {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

// Hover intent menu initialization
$(function () {
    function addSubmenu() {
        $(".nivoSlider").css("z-index", "-10"); // push slider image behind hover menu
        $(this).addClass("hovering");
    }
    function removeSubmenu() {
        $(this).removeClass("hovering");
        $(".nivoSlider").css("z-index", ""); // reset slider z-index to make navigation buttons work
    }
    var submenuConfig = {
        interval: 300,
        sensitivity: 4,
        over: addSubmenu,
        timeout: 300,
        out: removeSubmenu
    };
    $("li.submenu").hoverIntent(submenuConfig)
});

// Hover intent menu url initialization
$(function () {
    var loc = window.location.toString().split("/");
    var page = loc[loc.length - 1];
    var tab = loc[loc.length - 2];
    var path = "/" + tab + "/" + page;  /* update before moving to production */
    var selectedpage = $("li.submenu a[href=\"" + path + "\"]");
    if (selectedpage !== null) {
        selectedpage.parent().parent().addClass("selectedsubmenu");
    }
});

// Slider initialization
$(function () {
    $('#slider').nivoSlider({
        effect: 'random', // Specify sets like: 'fold,fade,sliceDown'
        slices: 15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed: 500, // Slide transition speed
        pauseTime: 3000, // How long each slide will show
        startSlide: 0, // Set starting Slide (0 index)
        directionNav: true, // Next & Prev navigation
        directionNavHide: true, // Only show on hover
        controlNav: false, // 1,2,3... navigation
        controlNavThumbs: false, // Use thumbnails for Control Nav
        pauseOnHover: true, // Stop animation while hovering
        manualAdvance: false, // Force manual transitions
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        randomStart: true, // Start on a random slide
        beforeChange: function () { }, // Triggers before a slide transition
        afterChange: function () { }, // Triggers after a slide transition
        slideshowEnd: function () { }, // Triggers after all slides have been shown
        lastSlide: function () { }, // Triggers when last slide is shown
        afterLoad: function () { } // Triggers when slider has loaded
    });
});

var ctef = ctef || {
    initializeForm: function (formSelector, messageSelector) {
        var form = $(formSelector);
        var button = form.find(':submit');
        var message = $(messageSelector);
        button.click(function (event) {
            event.preventDefault();
            message.html("");
            $(this).attr('disabled', 'disabled');
            $.post(form.attr('action'), form.serialize(),
                function (data, status) {
                    if (status == 'success') {
                        if (data["success"]) {
                            form.hide();
                        }
                        else {
                            button.removeAttr('disabled');
                        }
                        message.html(data["message"]);
                    }
                });
        });
    }
};
